package oktx.feign.config;

import oktx.feign.interceptor.HttpRequestInterceptor;
import org.springframework.cloud.client.loadbalancer.RestTemplateCustomizer;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.web.client.RestTemplate;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by huangdachao on 2018/5/31 17:46.
 */
public class RestTemplateCustomizerWrapper implements RestTemplateCustomizer {
    private RestTemplateCustomizer customizer;

    public RestTemplateCustomizerWrapper(RestTemplateCustomizer customizer) {
        this.customizer = customizer;
    }

    @Override
    public void customize(RestTemplate restTemplate) {
        customizer.customize(restTemplate);
        List<ClientHttpRequestInterceptor> list = new ArrayList<>(restTemplate.getInterceptors());
        list.add(new HttpRequestInterceptor());
        restTemplate.setInterceptors(list);
    }
}
